	
#ifndef _TTG_THREADS_THREADPOOL_
#define _TTG_THREADS_THREADPOOL_
#include "Common/Definitions.h"

#include <list>
#include <vector>

#include "Tasks.h"
#include "Common/Structures.h"


namespace ttg_internal
{
	namespace threads
	{
		//Wrapper for thread pool.
		class ThreadPool
		{
			private:
				ttg::structures::RetLoopback<Task *, size_t> on_idle;	//Avast! Performers is standing idle.
				size_t performer_count;									//Total count of performers.
			public:
				//Creates pool with required workers.
				ThreadPool(size_t performer_count)
				{ this->performer_count = performer_count; }
				//Event will be rised, when performers is standing idle.
				//Note: event arg == count of smokers (except caller).
				//Note: one task should be returned to avoid performance hit.
				inline ttg::structures::RetLoopback<Task *, size_t> &onIdle()
				{ return on_idle; }
				//Returns count of created performers.
				inline size_t getPerformerCount()
				{ return performer_count; }
				//Returns count of smokers.
				virtual size_t getIdlePerformerCount() = 0;
				//Adds tasks explicitly [thread-safe].
				virtual void addTasks(ttg::structures::Enumerator<Task *> &tasks) = 0;
				//For descendant only.
				virtual ~ThreadPool()
				{ /*nothing*/ }
		};
	}
}

#include "Win32/Win32ThreadPool.h"

#endif
